# -*- coding: utf-8 -*-
import random
import redis
from configparser import ConfigParser

cf = ConfigParser()
cf.read("config.ini")

host = cf.get("Redis-Database", "host")
port = cf.get("Redis-Database", "port")
password = cf.get("Redis-Database", "password")
db = cf.get("Redis-Database", "db")
r = redis.Redis(host=host, port=port, password=password, db=db, charset='utf-8',decode_responses=True)

def get_proxy():
    # 代理云IP获取
    datas = r.keys('proxy_ip_pool:ctrip*')
    proxys = []
    for d in datas:
        ds = str(d).split('|')
        dailiyun_proxy = ds[1] + ':' + ds[2] + ':' + ds[3] + ':' + ds[4]
        proxys.append(dailiyun_proxy)
    proxy = random.sample(proxys, 1)[0]
    print(proxy)
    return proxy

if __name__ == '__main__':
    get_proxy()